package com.kzj.fun.interfaces.impl;

import com.kzj.fun.container.root.RootPanel;
import com.kzj.fun.enums.PaintType;
import com.kzj.fun.interfaces.MenuFunction;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.HashMap;
import java.util.Map;

public class MouseListenerPack implements MouseListener, MouseMotionListener {
    private RootPanel rootPanel;
    private Map<PaintType, MenuFunction> map=new HashMap<>();
    public MouseListenerPack(RootPanel rootPanel){
        this.rootPanel=rootPanel;
        map.put(PaintType.NULL,rootPanel);
        map.put(PaintType.LINE,new PaintLineMenuFunction(rootPanel));
        map.put(PaintType.ELLIPSE,new PaintEllipseMenuFunction(rootPanel));
        map.put(PaintType.RECT,new PaintRectFunction(rootPanel));
        map.put(PaintType.FILL_ELLIPSE,new PaintFillEllipseMenuFunction(rootPanel));
        map.put(PaintType.FILL_RECT,new PaintFillRectFunction(rootPanel));
        map.put(PaintType.PAINT_BRUSH,new PaintBrushPaintFunction(rootPanel));
    }
    @Override
    public void mouseClicked(MouseEvent e) {
        map.get(rootPanel.getPaintType()).mouseClicked(e);
    }

    @Override
    public void mousePressed(MouseEvent e) {
        map.get(rootPanel.getPaintType()).mousePressed(e);
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        map.get(rootPanel.getPaintType()).mouseReleased(e);
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        map.get(rootPanel.getPaintType()).mouseEntered(e);
    }

    @Override
    public void mouseExited(MouseEvent e) {
        map.get(rootPanel.getPaintType()).mouseExited(e);
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        map.get(rootPanel.getPaintType()).mouseDragged(e);
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        map.get(rootPanel.getPaintType()).mouseMoved(e);
    }
}
